


setTimeout(() => {
    location.reload()
},3600000);

console.log("create collect");
setTimeout(() => {
    $.ajax({
        url: "http://www.ozonzhuli.com/index.php?c=api/neiyi/get_collect_skus",
        success: function (data) {
            console.log(data);
            if (data.data.ozon_sku_id) {
                createCollect(data.data.ozon_sku_id, data.data.collect_id, data.data.create_date,data.data.title);
            }
        }
    });
}, 2000);

function createCollect(ozon_sku_id,collect_id,create_date,title){

    if(collect_id > 0){
        addSkuToCollect(collect_id,ozon_sku_id);
        return;
    }

    // 获取当前时间
    const currentDate = new Date();

    // 设置开始时间为今天的0点0分
    const startDate = new Date(currentDate);
    startDate.setHours(0, 0, 0, 0); // 设置为0点0分

    // 设置结束时间为365天后的0点0分
    const endDate = new Date(currentDate);
    endDate.setDate(currentDate.getDate() + 365); // 计算365天后
    endDate.setHours(0, 0, 0, 0); // 设置为0点0分

    // 格式化时间为 ISO 8601 格式
    const startTimeISO = startDate.toISOString();
    const endTimeISO = endDate.toISOString();

    // 请求参数
    const data = {
        highlight: {
            type: "STATIC",
            title: title,
            start_time: startTimeISO,
            end_time: endTimeISO,
            source_type: "SOURCE_TYPE_SELLER"
        }
    };

    // 发送 AJAX 请求
    $.ajax({
        url: 'https://seller.ozon.ru/api/site/seller-highlights/v1/highlights',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify(data),
        xhrFields: {
            withCredentials: true // 设置为支持跨域请求时带上凭证
        },
        headers: {
            'accept': 'application/json, text/plain, */*',
            'accept-language': 'zh-Hans',
            'origin': 'https://seller.ozon.ru',
            'priority': 'u=1, i',
            'referer': 'https://seller.ozon.ru/app/seller-highlights/create/static',
            'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"macOS"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
            'x-o3-app-name': 'seller-ui',
            'x-o3-company-id': '1274960',
            'x-o3-language': 'zh-Hans',
            'x-o3-page-type': 'seller-highlights'
        },
        success: function(response) {
            console.log("成功:", response);
            var collect_id = response['highlight']['id'];
            if(collect_id){
                $.ajax({
                    url: "http://www.ozonzhuli.com/index.php?c=api/neiyi/post_collect_id&collect_id="+collect_id+"&create_date="+create_date,
                    success: function (data) {
                        console.log(data);
                    }
                });
                addSkuToCollect(collect_id,ozon_sku_id);
            }
        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.error("请求失败:", textStatus, errorThrown);
        }
    });

}

function addSkuToCollect(collect_id,ozon_sku_id){

    const data = {
        inserted_sku: ozon_sku_id,
        removed_sku: []
    };

    // 发送 AJAX 请求
    $.ajax({
        url: 'https://seller.ozon.ru/api/site/seller-highlights/v1/highlights/'+collect_id+'/skus',
        type: 'PUT',
        contentType: 'application/json',
        data: JSON.stringify(data),
        xhrFields: {
            withCredentials: true //设置为支持跨域请求时带上凭证
        },
        headers: {
            'accept': 'application/json, text/plain, */*',
            'accept-language': 'zh-Hans',
            'origin': 'https://seller.ozon.ru',
            'priority': 'u=1, i',
            'referer': 'https://seller.ozon.ru/app/seller-highlights/create/static',
            'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"macOS"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
            'x-o3-app-name': 'seller-ui',
            'x-o3-company-id': '1274960',
            'x-o3-language': 'zh-Hans',
            'x-o3-page-type': 'seller-highlights'
        },
        success: function(response) {

            console.log("成功:", response);

        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.error("请求失败:", textStatus, errorThrown);
        }
    });



}


